from typing import List
from datetime import datetime
# The Python Standard Modules(Library) and Third Modules(Library)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, UniqueConstraint,func,Integer, String, Date,Float,Boolean,DateTime
from sqlalchemy.orm import Mapped,mapped_column 

from sqlalchemy.orm import Mapped,mapped_column,relationship,backref

from . import MappedBase
# from databases.sqlite import MappedBase




# ================================== 一对多 ================================== #
class Dev(MappedBase):
    __tablename__ = 'dev'


    id:Mapped[int]=mapped_column(primary_key=True, index=True, autoincrement=True, comment='机台id,自动生成')

    dev_no: Mapped[str] = mapped_column(Integer, unique=True,  nullable=False,comment='机台编号')
    type:Mapped[str] = mapped_column(String(100), unique=False,nullable=False,comment='机台种类')
    cv_type:Mapped[str] = mapped_column(String(100), unique=False,nullable=False,comment='ocr的类型')
    state:Mapped[str] = mapped_column(String(10), unique=False,nullable=True,comment='机台的状态')
    state_color:Mapped[str] = mapped_column(String(10), unique=False,nullable=True,comment='state color')


    # 站点的x坐标,可以为空,有时候就是没有,默认设置成0
    temperature: Mapped[float] = mapped_column(Float, nullable=True ,comment='机台当前的温度,最近一次截图的温度(可能不用,直接图片库里面查找最近一次的温度记录)',default=0)
    humidity: Mapped[float] = mapped_column(Float, nullable=True ,comment='机台的湿度',default=0)

    logo_height: Mapped[float] = mapped_column(Float, nullable=True,comment='机台标识距离地面的高度(cm)')
    logo_size:Mapped[float] = mapped_column(Float, nullable=True,comment='机台标识的大小(cm)')
    monitor_height: Mapped[float] = mapped_column(Float, nullable=True,comment='机台显示屏距离地面的高度(cm)')

    monitor_size_width:Mapped[float] = mapped_column(Float,nullable=True,comment='机台显示屏的大小(cm)宽度')
    monitor_size_height:Mapped[float] = mapped_column(Float,nullable=True,comment='机台显示屏的大小(cm)高度')

    dashboard_height:Mapped[float] = mapped_column(Float,nullable=True,comment='机台圆边表盘距离地面的高度(cm)')
    dashboard_size:Mapped[float] = mapped_column(Float,nullable=True, comment='机台圆边表盘的大小(cm)')

    update_time:Mapped[datetime] = mapped_column(DateTime(timezone=True),nullable=True, comment='最近一次拍照的时间')



    # stations:Mapped[List['Station']]= relationship('Station',back_populates='dev', cascade='all, delete-orphan',lazy="joined")
    # stations:Mapped[List['Station']]= relationship('Station',back_populates='dev', cascade='all, delete-orphan')
    # devs: Mapped[List['Dev']] = relationship(back_populates='station',cascade="all,delete-orphan")
    # imgs: Mapped[List['Img']] = relationship(back_populates='dev',cascade="all,delete-orphan")




    


